home *** CD-ROM | disk | FTP | other *** search
- /*
- Walk.c
-
- Animated walking figure on balcony
-
- Copyright 1993 by Al Evans. All rights reserved.
-
- 11/8/93
-
- */
-
- #include "Walk.h"
- #include "Motion.h"
- #include "SFXCtrlr.h"
- #include "SFXProcs.h"
-
- #undef COMMERCIALRELEASE
-
-
- #ifdef COMMERCIALRELEASE
- pascal void DisposeWalker(GEWorldPtr world, GrafElPtr walker)
- {
- if (walker->drawData)
- DisposPtr(walker->drawData);
- if (walker->changeData)
- DisposPtr(walker->changeData);
- }
- #endif
-
-
- Boolean LoadBalconyScene(GEWorldPtr world)
- {
- GrafElPtr thisElement;
- Rect balconyBox; //Walking figure positioned relative to balcony
- short elemHeight;
- MParamPtr walkMotion;
-
- //Get railing of balcony
- thisElement = NewBasicPICT(world, balconyID, balconyPlane, rBalconyPic,
- transparent, balconyLeft, balconyTop);
- if (thisElement == nil) return false;
- balconyBox = thisElement->animationRect;
-
- //Get walking figure
- thisElement = NewAnimatedGraphic(world, walkID, walkPlane, rAnimWalk,
- transparent, 0, 0, 10);
- if (thisElement == nil) return false;
-
- #ifdef COMMERCIALRELEASE
- //Draw walker masked
- thisElement->drawData = MakeMask(&((GrafPtr) thisElement->graphWorld)->portBits);
- thisElement->copyMode = srcCopy;
-
- //Be sure to dispose mask & motion
- SetCleanupProc(world, walkID, DisposeWalker);
- #endif
-
- //Position figure relative to balcony
- elemHeight = thisElement->graphRect.bottom - thisElement->graphRect.top;
- PtrMoveElementTo(world, thisElement, balconyBox.left + ScaleToWorld(world, 20),
- balconyBox.bottom - ScaleToWorld(world, 10) - elemHeight, false);
-
- //Initialize motion fields -- never collide with top or bottom
- walkMotion = (MParamPtr) NewPtrClear(sizeof(MotionParams));
- InitMotion(walkMotion, 100, 100);
- walkMotion->currMotion.h = 6;
- walkMotion->limitRect.top = 0;
- walkMotion->limitRect.left = balconyBox.left + ScaleToWorld(world, 5);
- walkMotion->limitRect.bottom = 1000;
- walkMotion->limitRect.right = balconyBox.right - ScaleToWorld(world, 16);
-
- //Initialize figure's walking action
- SetAutoChange(world, walkID, DoWalker, (Ptr) walkMotion, 133);
-
- //And set animation style to "loop"
- ((SeqGraphicPtr) thisElement)->seq = loop;
-
- //Load speed control slider
- thisElement = NewSliderSensor(world, sliderID, sliderPlane, rSliderBkg,
- sliderLeft, sliderTop, hSlideSensor, rSliderCtrl);
- if (thisElement == nil) return false;
- SetSliderPercent(world, sliderID, 50);
- SetSensorAction(world, sliderID, AdjustSpeed);
- (void) DoGESFX(world, 'SFX1', thisElement, SFXHWipe, 30, 3000, 40, true, true);
-
- return true;
- }
-
-
- pascal void DoWalker(GEWorldPtr world, GrafElPtr walker)
- {
- MParamPtr motion;
- GEDirection collisionDir;
-
- motion = (MParamPtr) walker->changeData;
- collisionDir = CheckLimits(&walker->animationRect, &motion->limitRect);
- if ((collisionDir == left) || (collisionDir == right)) {
- motion->currMotion.h = -motion->currMotion.h;
- SetMirroring(world, walker->objectID, (collisionDir == right), false);
- }
- MoveElement(world, walker->objectID, motion->currMotion.h, motion->currMotion.v);
- BumpFrame(world, walker->objectID);
- }
-
- pascal void AdjustSpeed(GEWorldPtr world, short newSpeed)
- {
- GrafElPtr walker;
- long newIntrvl;
-
- walker = FindElementByID(world, walkID);
- if (walker) {
- newIntrvl = (newSpeed * 240) / 100;
- if (newIntrvl > 0) {
- newIntrvl = 240 - newIntrvl;
- if (newIntrvl < 16)
- newIntrvl = 16;
- }
- walker->changeIntrvl = newIntrvl;
- }
- }
-